package com.kkb.shopcenter.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.shopcenter.api.BrandService;
import com.kkb.shopcenter.common.pojo.BrandInfo;
import com.kkb.shopcenter.server.mappers.BrandInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {



    @Autowired
    private BrandInfoMapper brandInfoMapper;

    @Override
    public PageInfo<BrandInfo> getBrand(Integer pageNo, Integer pageSize) {

        PageHelper.startPage(pageNo,pageSize);
        Example example = new Example(BrandInfo.class);
        example.setOrderByClause("id DESC");
        List<BrandInfo> allBrandList = brandInfoMapper.selectByExample(example);
        PageInfo<BrandInfo> pageInfo = new PageInfo<>(allBrandList);
        return  pageInfo;
    }

    @Override
    public List<BrandInfo> getAllBrand() {

        Example example = new Example(BrandInfo.class);
        example.createCriteria().andEqualTo("deleteFlag",false);
        List<BrandInfo> allBrandList = brandInfoMapper.selectByExample(example);
        return   brandInfoMapper.selectAll();
    }


    public int insertBrand(BrandInfo record){

        return brandInfoMapper.insertSelective(record);
    }

    public int updateBrand(BrandInfo record){

        return brandInfoMapper.updateByPrimaryKeySelective(record);
    }

    public int deleteBrand(int id){
        return brandInfoMapper.deleteByPrimaryKey(id);
    }
}
